package com.mySchool.controller;

import com.mySchool.entity.*;
import com.mySchool.service.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
* @author : Hinton
* @date : 2024/10/18 上午8:16
*/
@RestController
@RequestMapping("/Library")
public class LibraryController {
    @Autowired
    private LibraryService libraryService;


    @GetMapping("/findAll")
    public List<Library> findAll() {
        return libraryService.findAll();
    }

    @GetMapping("/findById")
    public Library findById(Long id) {
        return libraryService.findById(id);
    }

    @GetMapping("/findByName")
    public List<Library> findByName(@RequestParam String name) {
        return libraryService.findByName(name);
    }

    @GetMapping("/findDetail")
    public Result findDetail(@RequestParam String name) {
        List<Library> result = libraryService.findDetail(name);
        if (result.isEmpty()) {
            return Result.error("未找到该图书馆");
        }
        return Result.success(result);
    }

    @GetMapping("/findBelow")
    public Result findBelow(@RequestParam String name, @RequestParam Integer pageNumber) {
        List result = libraryService.findBelow(name, pageNumber);
        if (result.isEmpty()) {
            return Result.error("未找到该图书管下的信息");
        }
        return Result.success(result);
    }
}
